package com.ctgu.service.impl;

import com.ctgu.mapper.UserMapper;
import com.ctgu.service.UserService;
import com.ctgu.vo.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;


    @Override
    public User getById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<User> getAllStudentDetail() {
        return userMapper.getAllStudentDetail();
    }

    @Override
    public List<User> getAllTeacherDetail() {
        return userMapper.getAllTeacherDetail();
    }

    @Override
    public int initPassword(Integer userId) {
        User user = new User();
        user.setUserId(userId);
        user.setPassword("123456");
        return userMapper.updateByPrimaryKeySelective(user);
    }

    @Override
    public int deleteUser(Integer userId) {
        return userMapper.deleteByPrimaryKey(userId);
    }

    @Override
    public int addUser(Integer userId, Integer type) {
        User user = new User();
        user.setUserId(userId);
        user.setPassword("123456");
        user.setType(type);
        return userMapper.insert(user);
    }
}
